﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Gueei.Gallery.Core.Repositories;

namespace Gueei.Gallery.Web.Controllers
{
	public class SearchController : Controller
	{
		private readonly ITagRepository _tagRepo;

		public SearchController(ITagRepository tagRepo)
		{
			_tagRepo = tagRepo;
		}

		public ActionResult Index()
		{
			return View();
		}

		public ActionResult Tags(string term)
		{
			var tags = _tagRepo.GetTags().Where(t => t.Name.Contains(term));
			return new JsonResult() {
				JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet,
				Data = tags.Select(t => new {
					id=t.Id,
					label=t.Name,
					value=t.Name
				})
			};
		}
	}
}
